#ifndef _FREEBOUNDARY_H_
#define _FREEBOUNDARY_H_

#include <stdlib.h>
#include <string.h>
#include <math.h>

#include "cfd_utils.h"
#include "visual.h"


/**
 * Initializes the particles which corresponds to the given problem
 *
 * @param	problem	The problem type (e.g. falling_drop, breaking_dam, etc...)
 * @param	N	The number of lists to be contained with the allocated particle lists
 * @param	ppc	The number of potential initial particle positions per cell with the same y-coordinates
 * @param 	dx 	length of one cell in x-direction
 * @param 	dy 	length of one cell in y-direction
 * @param 	imax 	Number of interior cells in x-direction
 * @param 	jmax 	Number of interior cells in y-direction
 * @param 	U 	The velocity in x-direction
 * @param 	V 	The velocity in y-direction
 * @param	npart	The total number of particles
 *
 * @return	A pointer to the allocated particles list
 */
struct particle_line *init_particle (
					char 	*problem,
					int 	*N,
					int 	ppc,
					double 	dx,
					double 	dy,
					int 	imax,
					int 	jmax,
					double 	**U,
					double 	**V,
					int 	*npart
				);


/**
 * Marks all the cells within Flag with the appropiate marker.
 *
 * @param	Flag		The markers matrix
 * @param 	dx 		length of one cell in x-direction
 * @param 	dy 		length of one cell in y-direction
 * @param 	imax 		Number of interior cells in x-direction
 * @param 	jmax 		Number of interior cells in y-direction
 * @param	NP		The total number of particles
 * @param	Particle_Lines	A pointer to the particles list
 */
void mark_cells(
		int 	**Flag,
		double 	dx,
		double 	dy,
		int 	imax,
		int 	jmax,
		int 	NP,
		struct particle_line *Particle_Lines
		);


/**
 * Calculates the boundary values for U, V, and P.
 *
 * @param	dt	The time step used for solving the problem
 * @param 	dx 	length of one cell in x-direction
 * @param 	dy 	length of one cell in y-direction
 * @param 	imax 	Number of interior cells in x-direction
 * @param 	jmax 	Number of interior cells in y-direction
 * @param	Re	Reynold's Number
 * @param 	U 	The velocity in x-direction
 * @param 	V 	The velocity in y-direction
 * @param	P	The pressure matrix
 * @param	Flag	The markers matrix
 * @param	GX	X-component of the external forces
 * @param	GY	Y-component of the external forces
 */
void set_uvp_rand (
			double 	dt,
			double 	dx,
			double 	dy,
			int 	imax,
			int 	jmax,
			double 	Re,
			double 	**U,
			double 	**V,
			double 	**P,
			int 	**Flag,
			double 	GX,
			double 	GY
		);


/**
 * Checks if the given (x,y) lies inside the circle given by (center_x,center_y) and radius or not
 *
 * @param	center_x	X-coordinate of the center of the circle
 * @param	center_y	Y-coordinate of the center of the circle
 * @param	radius		Radius of the circle
 * @param	x		The X-coordinate of the point to be checked
 * @param	y		The Y-coordinate of the point to be checked
 *
 * @return	1 if the point given by (x,y) is inside the circle, 0 otherwise
 */
inline int is_inside_circle (	double center_x,
				double center_y,
				double radius,
				double x,
				double y
				);

#endif /*FREEBOUNDARY_H_*/
